<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
	xmlns:c="http://java.sun.com/jstl/core" xmlns:a4j="http://richfaces.org/a4j"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:t="https://code.google.com/p/rad-framework/taglib"
	xmlns:tt="https://code.google.com/p/rad-framework"
	xmlns:s="http://jboss.com/products/seam/taglib">
	
	<c:set var="rendered" value="#{t:rendered(entity,id)}"/>
	
	<h:outputLabel value="#{label}" rendered="#{rendered}"
		styleClass="#{t:required(entity,id) ? 'rad-framework-form-label-required' : 'rad-framework-form-label'}"/>
	
	<s:fragment rendered="#{rendered}">
		<s:decorate id="#{id}Decor">
			<c:choose>
				<c:when test="#{type == 'String'}">
					<h:inputText id="#{id}" value="#{value}"
						disabled="#{t:disabled(entity,id)}"
						required="#{t:required(entity,id)}"
						maxsize="#{t:length(entity,id)}"
						size="#{t:size(entity,id)}"
						styleClass="#{t:required(entity,id) ? 'rad-framework-form-input-field-required' : 'rad-framework-form-input-field'}">
					</h:inputText>
				</c:when>
				
				<c:when test="#{type == 'Date'}">
					<rich:calendar id="#{id}" value="#{value}"
						disabled="#{t:disabled(entity,id)}"
						required="#{t:required(entity,id)}"
						locale="#{org.jboss.seam.core.locale}"
						timeZone="#{org.jboss.seam.international.timeZone}"
						datePattern="MM/dd/yyyy" enableManualInput="true"
						inputClass="#{t:required(entity,id) ? 'rad-framework-form-input-field-required' : 'rad-framework-form-input-field'}">
					</rich:calendar>
				</c:when>
				
				<c:when test="#{type == 'Boolean'}">
					<h:selectBooleanCheckbox id="#{id}" value="#{value}"
						disabled="#{t:disabled(entity,id)}"
						required="#{t:required(entity,id)}"
						styleClass="#{t:required(entity,id) ? 'rad-framework-form-input-field-required' : 'rad-framework-form-input-field'}">
					</h:selectBooleanCheckbox>
				</c:when>
				
				<c:when test="#{type == 'TextArea'}">
					<tt:editor id="#{id}" value="#{value}"
						disabled="#{t:disabled(entity,id)}"
						required="#{t:required(entity,id)}">
					</tt:editor>
				</c:when> 
				<c:when test="#{type == 'Enum'}">
					<h:selectOneMenu id="#{id}" value="#{value}"
						required="#{t:required(entity,id)}"
						disabled="#{t:disabled(entity,id)}"
						styleClass="rad-framework-form-field">
						
						<c:if test="#{!t:required(entity,id)}">
							<f:selectItem itemValue=""/>
						</c:if>
						
						<f:selectItems value="#{t:enumConstants(entity,id)}"/>
						
						<a4j:support ajaxSingle="true" event="onchange"
							rendered="#{not empty t:reRender(entity,id)}"
							reRender="#{t:reRender(entity,id)}">
							<s:conversationId/>
						</a4j:support>
						
					</h:selectOneMenu>
				</c:when>
				
				<c:when test="#{type == 'Integer'}">
					<rich:inputNumberSpinner id="#{id}" value="#{value}"
						disabled="#{t:disabled(entity,id)}"
						required="#{t:required(entity,id)}"
						maxValue="#{t:max(entity,id)}"
						minValue="#{t:min(entity,id)}"
						size="#{t:size(entity,id)}"
						styleClass="#{t:required(entity,id) ? 'rad-framework-form-input-field-required' : 'rad-framework-form-input-field'}">
					</rich:inputNumberSpinner>
				</c:when>
				
				<c:when test="#{type == 'Decimal'}">
					<h:inputText id="#{id}" value="#{value}"
						disabled="#{t:disabled(entity,id)}"
						required="#{t:required(entity,id)}"
						maxValue="#{t:max(entity,id)}"
						minValue="#{t:min(entity,id)}"
						size="#{t:size(entity,id)}"
						styleClass="#{t:required(entity,id) ? 'rad-framework-form-input-field-required' : 'rad-framework-form-input-field'}">
					</h:inputText>
				</c:when>
				
				<c:when test="#{type == 'Currency'}">
					<h:inputText id="#{id}" value="#{value}"
						disabled="#{t:disabled(entity,id)}"
						required="#{t:required(entity,id)}"
						size="#{t:size(entity,id)}"
						styleClass="#{t:required(entity,id) ? 'rad-framework-form-input-field-required' : 'rad-framework-form-input-field'}">
					</h:inputText>
				</c:when>
				
				<c:when test="#{type == 'Percent'}">
					<h:inputText id="#{id}" value="#{value}"
						disabled="#{t:disabled(entity,id)}"
						required="#{t:required(entity,id)}"
						size="#{t:size(entity,id)}"
						styleClass="#{t:required(entity,id) ? 'rad-framework-form-input-field-required' : 'rad-framework-form-input-field'}">
						<f:converter
							converterId="rad.framework.jsf.PercentConverter"/>
					</h:inputText>
				</c:when>
				
				<c:when test="#{type == 'Timestamp'}">
					<h:inputText id="#{id}" value="#{value}" disabled="true"
						required="false" 
						size="28"
						styleClass="rad-framework-form-input-field">
						<s:convertDateTime type="both" dateStyle="short"
							timeStyle="short"
							pattern="#{messages['TimestampPattern']}"/>
					</h:inputText>
				</c:when>
				
				<c:when test="#{type == 'Blob'}">
					<s:fileUpload id="#{id}" data="#{value.content}"
						fileName="#{value.name}" fileSize="#{value.size}"
						contentType="#{value.contentType}"
						disabled="#{t:disabled(entity,id)}"
						required="#{t:required(entity,id)}"
						styleClass="#{t:required(entity,id) ? 'rad-framework-form-input-field-required' : 'rad-framework-form-input-field'}">
					</s:fileUpload>
				</c:when>
				
				<c:otherwise>
					<h:inputText id="#{id}" value="#{value}" disabled="true"
						styleClass="#{t:required(entity,id) ? 'rad-framework-form-input-field-required' : 'rad-framework-form-input-field'}">
					</h:inputText>
				</c:otherwise>
			</c:choose>

			<h:panelGroup>
			<rich:spacer width="5" height="1" />

			<h:graphicImage id="helpIcon" value="#{messages['HelpIcon']}"
				border="0" />
			<rich:toolTip direction="top-right" styleClass="tooltip"
				layout="block" for="helpIcon">
				<h:panelGrid>
					<h:outputText value="#{title}" />
				</h:panelGrid>
			</rich:toolTip>
			</h:panelGroup>

		</s:decorate>
	</s:fragment>
</ui:composition>